import { ArgumentsHost, Catch, ExceptionFilter, HttpException } from "@nestjs/common";
import { Response } from "express";

@Catch(HttpException)
export class HttpExceptionFilter  implements ExceptionFilter{
    catch(exception: any, host: ArgumentsHost) {
        const context = host.switchToHttp()
        const response =  context.getResponse<Response>()
        const code = exception.getStatus()
        const message = exception.message
        response.status(code).json({
            code,
            message
        }) 
        // throw new Error("Method not implemented.");
    }
    
}
